package ph.com.gs3.chat.managers;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import ph.com.gs3.chat.model.valueobject.business.Message;
import ph.com.gs3.chat.model.valueobject.business.UserStub;

public class PendingMessagesManager {

	public static final String TAG = PendingMessagesManager.class.getSimpleName();

	private Map<String, List<String>> pendingMessages;

	private static PendingMessagesManager defaultInstance;

	public static PendingMessagesManager getDefaultInstance() {
		if (defaultInstance == null) {
			defaultInstance = new PendingMessagesManager();
		}

		return defaultInstance;
	}

	public PendingMessagesManager() {
		pendingMessages = new HashMap<>();
	}

	public void appendPendingMessage(Message message) {

		UserStub author = message.getAuthor();

		if (!pendingMessages.containsKey(author.getId())) {
			pendingMessages.put(author.getId(), new ArrayList<String>());
		}

		pendingMessages.get(author.getId()).add(message.getMessage());

	}

	public void clearPendingMessage(String authorId) {

		pendingMessages.get(authorId).clear();

	}

	public List<String> getPendingMessages(String authorId) {
		return pendingMessages.get(authorId);
	}

}
